home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / dm3_src.zip / DMMON.C < prev    next >
Text File  |  1990-04-07  |  8KB  |  245 lines

  1. /* ************************************************************************* */
  2. /*                                                                           */
  3. /*           D O O R W A R E   M O N I T O R   I / O   L I R A R Y           */
  4. /*                                                                           */
  5. /*                          For Mycrosoft & Turbo C                          */
  6. /*                                                                           */
  7. /* ************************************************************************* */
  8.  
  9.  
  10.  
  11. /* ************************************************************************* */
  12. /*                            PROGRAM HISTORY                                */
  13. /* ************************************************************************* */
  14. /* 06/20/87     Version 1.00                                                 */
  15. /* 06/14/88     Version 1.10                                                 */
  16. /*              Change monitor function to not change directory              */
  17. /*              Change monitor function to build POINTSx.DOR in local dir    */
  18. /*                                                                           */
  19. /*                                                                           */
  20. /*                                                                           */
  21. /*                                                                           */
  22. /* ************************************************************************* */
  23.  
  24.  
  25.  
  26. #include "dmcfg.h"                              /* Std. defines & includes   */
  27. #include "dmdata.h"                             /* Std DM storage            */
  28.  
  29.  
  30. /*
  31.  *
  32.  * Read the monitor data
  33.  *
  34.  */
  35.  
  36. mon_read(node)
  37.  
  38. int     node;                                   /* Monitor node number       */
  39. {
  40. FS      rfd;
  41.  
  42. long    cur_time();
  43. char    nodestr[3];
  44. long    ctm;
  45.  
  46. int     i;
  47.  
  48.  
  49.    sprintf(nodestr, "%d", node);                /* Convert node to string    */
  50.  
  51.    strcpy(rfd.name ,"timeoff");                 /* Build the filename        */
  52.    strcat(rfd.name, nodestr);
  53.    strcat(rfd.name, ".dor");
  54.  
  55.    i = file_open(&rfd, FREAD, FTEXT, FNOCREATE); /* Open TIMEOFFx.DOR        */
  56.    if(i == 0)
  57.    {
  58.      if(fgets(dminbuff, 255, rfd.fd) != 0)
  59.      {
  60.        mon_signoff = atol(dminbuff);
  61.        if(fgets(dminbuff, 255, rfd.fd) != 0)
  62.        {
  63.          mon_user = atoi(dminbuff);
  64.          if(fgets(dminbuff, 255, rfd.fd) != 0)
  65.          {
  66.            mon_points = atoi(dminbuff);
  67.            if(fgets(dminbuff, 255, rfd.fd) != 0)
  68.            {
  69.              mon_max_play = atoi(dminbuff);
  70.              if(fgets(dminbuff, 255, rfd.fd) != 0)
  71.              {
  72.                mon_nulls = atoi(dminbuff);
  73.                if(fgets(dminbuff, 255, rfd.fd) != 0)
  74.                {
  75.                  mon_graphics = atoi(dminbuff);
  76.                  if(fgets(dminbuff, 255, rfd.fd) != 0)
  77.                  {
  78.                    strcpy(mon_dir, dminbuff);
  79.                    if(fgets(dminbuff, 255, rfd.fd) != 0)
  80.                    {
  81.                      strcpy(mon_sound, dminbuff);
  82.                    }
  83.                  }
  84.                }
  85.              }
  86.            }
  87.          }
  88.        }
  89.      }
  90.      file_close(&rfd);
  91.      mon_active     = 1;                        /* Flag as present           */
  92.  
  93.      user_start     = cur_time();               /* Remeber when we started   */
  94.      user_signoff   = mon_signoff;              /* time to signoff at        */
  95.      if(user_signoff < user_start)              /* adjust if wrap around     */
  96.        user_signoff = user_signoff + DAY_SECONDS;
  97. /* ***************************************************************************
  98.      ctm            = user_start + ((long)mon_max_play * 60L);
  99.      if(ctm < user_signoff)
  100.        user_signoff = ctm;
  101. *************************************************************************** */
  102.      user_nulls     = mon_nulls;                /* number of nulls required  */
  103.      user_graphics  = mon_graphics;             /* graphics flag             */
  104.      return(1);
  105.    }
  106.    else
  107.    {
  108.      mon_active = 0;                            /* Flag as not present       */
  109.      return(0);
  110.    }
  111. }
  112.  
  113.  
  114. /*
  115.  *
  116.  * Write the monitor data
  117.  *
  118.  */
  119.  
  120. mon_write(node, points)
  121.  
  122. int     node;                                   /* Monitor node number       */
  123. int     points;
  124. {
  125. FS      wfd;
  126.  
  127. long    cur_time();
  128. long    seconds;
  129.  
  130. char    nodestr[3];
  131. int     i;
  132.  
  133.    sprintf(nodestr, "%d", node);                /* Convert node to string    */
  134.  
  135.    if(mon_active)                               /* If monitor is there...    */
  136.    {
  137.      strcpy(wfd.name ,"points");
  138.      strcat(wfd.name, nodestr);
  139.      strcat(wfd.name, ".dor");
  140.  
  141.      i = file_open(&wfd, FWRITE, FTEXT, FCREATE); /* Create POINTSx.DOR      */
  142.      if(i == 0)                                 /* If file created OK...     */
  143.      {
  144.        seconds = cur_time();                    /* Time after midnight       */
  145.        fprintf(wfd.fd, "%lu\n", seconds);
  146.        fprintf(wfd.fd, "%u\n", points);         /* Score this game           */
  147.        file_close(&wfd);
  148.      }
  149.    }
  150.    return(0);                                   /* All done                  */
  151. }
  152.  
  153.  
  154. /*
  155.  *
  156.  * Read in the player name
  157.  *
  158.  */
  159.  
  160. mon_player(name, user)
  161.  
  162. char    *name;                                  /* Place to return name      */
  163. int     user;                                   /* User number               */
  164. {
  165. FS      rfd;                                    /* Players file descriptor   */
  166. long    location;                               /* File offset               */
  167. int     i;
  168.  
  169.    if(mon_active)                               /* If monitor is active...   */
  170.    {
  171.      i = 0;
  172.      while((mon_dir[i] != ' ')  &&              /* Build the filename        */
  173.            (mon_dir[i] != '\0') &&
  174.            (mon_dir[i] != 0x09) &&
  175.            (mon_dir[i] != 0x0a) &&
  176.            (mon_dir[i] != 0x0d))
  177.      {
  178.        rfd.name[i] = mon_dir[i];
  179.        i++;
  180.      }
  181.      if((i > 0) && (rfd.name[i - 1] != '\\') && (rfd.name[i - 1] != ':'))
  182.      {
  183.        rfd.name[i] = '\\';
  184.        i++;
  185.      }
  186.      rfd.name[i] = '\0';
  187.  
  188.      strcat(rfd.name, "NAMES.DOR");
  189.      i = file_open(&rfd, FREAD, FBINARY, FNOCREATE); /* Open the file        */
  190.      if(i == 0)                                 /* If open is OK             */
  191.      {
  192.        location = (long)(user - 1) * 64L;       /* Record location           */
  193.        if(fseek(rfd.fd, location, 0))           /* If we can't find the spot */
  194.        {
  195.          file_close(&rfd);                      /* Close the file            */
  196.          return(1);                             /* Exit, can't find name     */
  197.        }
  198.  
  199.        if(fread(dminbuff, 1, 64, rfd.fd) != 64)
  200.        {
  201.          file_close(&rfd);                      /* Close the file            */
  202.          return(1);                             /* Exit, can't find name     */
  203.        }
  204.  
  205.        for(i = 0 ; i < 31 ; i++)
  206.          name[i] = dminbuff[i];
  207.  
  208.        name[i] = '\0';
  209.        file_close(&rfd);                        /* Close the file            */
  210.        return(0);                               /* Return all OK             */
  211.      }
  212.      else
  213.        return(1);                               /* Exit, can't find name     */
  214.    }
  215.    else
  216.      return(2);                                 /* Flag as inactive          */
  217. }
  218.  
  219.  
  220. /*
  221.  *
  222.  * Return to the monitor
  223.  *
  224.  */
  225.  
  226. mon_exit(node)
  227.  
  228. int     node;
  229. {
  230. FS      wfd;
  231.  
  232. int     i;
  233. char    fname[80];
  234. char    nname[8];
  235.  
  236.    if(mon_active)                               /* If it is there...         */
  237.    {
  238.      strcpy(fname, "MONITOR1.EXE");
  239.      sprintf(nname, "%d", node);
  240.      i = spawnl(P_OVERLAY, fname, fname, nname, NULL);
  241.    }
  242.    return(0);                                   /* back to where we were     */
  243. }
  244.  
  245.